package com.example.vo;

import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
public class UserBalanceVO {
    
    private Long id;
    
    private Long userId;
    
    private String username; // 用户名（关联查询）
    
    private String nickname; // 昵称（关联查询）
    
    private BigDecimal balance; // 账户余额
    
    private BigDecimal frozenBalance; // 冻结余额
    
    private BigDecimal totalRecharge; // 累计充值金额
    
    private BigDecimal totalConsume; // 累计消费金额
    
    private BigDecimal availableBalance; // 可用余额（余额-冻结余额）
    
    private LocalDateTime createTime;
    
    private LocalDateTime updateTime;
    
    // 计算可用余额
    public BigDecimal getAvailableBalance() {
        if (balance == null) {
            return BigDecimal.ZERO;
        }
        if (frozenBalance == null) {
            return balance;
        }
        return balance.subtract(frozenBalance);
    }
}
